import {Component, OnInit} from '@angular/core';
import {ModalController, NavParams} from '@ionic/angular';
import {HttpService} from '../../services/http.service';
import {DomSanitizer} from '@angular/platform-browser';

@Component({
  selector: 'app-registry-agreement',
  templateUrl: './registry-agreement.component.html',
  styleUrls: ['./registry-agreement.component.scss']
})
export class RegistryAgreementComponent implements OnInit {

  content: any = {
    htmlTitle: '协议内容',
    html: ''
  };

  constructor(public navParams: NavParams,
              private modalCtrl: ModalController,
              private service$: HttpService,
              private sanitize: DomSanitizer
  ) {
  }

  ngOnInit() {
    const data = this.navParams.data;
    if (data['OPT']) {
      this.service$.doRequest(data['OPT'], {})
        .subscribe(obj => {
          if (obj) {
            this.content = obj;
          }
        });
    } else if (data['html']) {
      this.content['html'] = this.sanitize.bypassSecurityTrustHtml(data['html']);
    }
    if (data['title']) {
      this.content['title'] = data['title'];
    }
  }

  public closeModal() {
    this.modalCtrl.dismiss().catch(() => {
    });
  }

}
